package com.guli.mall.wms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.regex.Pattern;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guli.common.utils.PageUtils;

import com.guli.mall.wms.mapper.WareInfoMapper;
import com.guli.mall.wms.entity.WareInfoEntity;
import com.guli.mall.wms.service.WareInfoService;
import org.springframework.util.StringUtils;


@Service("wareInfoService")
public class WareInfoServiceImpl extends ServiceImpl<WareInfoMapper, WareInfoEntity> implements WareInfoService {

    @Override
    public PageUtils<WareInfoEntity> queryPage(Integer currentPage, Integer size, Map<String, String> params) {

        Page<WareInfoEntity> page = new Page<>(currentPage,size);


        QueryWrapper<WareInfoEntity> wrapper = new QueryWrapper<>();

        String key = params.get("key");

        if(!StringUtils.isEmpty(key)){

            if(Pattern.matches("^[0-9]+$",key)){
                wrapper.like("id",key).or().like("areacode",key);
            }else{
                wrapper.like("name",key).or().like("address",key);

            }

        }


        Page<WareInfoEntity> resultPage = this.page(page,wrapper);


        return new PageUtils<>(resultPage);
    }

}